package cn.ibizlab.odoo.core.odoo_rating.service.impl;

import java.io.Serializable;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.HashMap;
import java.math.BigInteger;
import java.util.Collection;

import lombok.extern.slf4j.Slf4j;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cglib.beans.BeanCopier;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import cn.ibizlab.odoo.core.client.model.Irating_mixin;
import cn.ibizlab.odoo.core.odoo_rating.domain.Rating_mixin;
import cn.ibizlab.odoo.core.odoo_rating.filter.Rating_mixinSearchContext;
import cn.ibizlab.odoo.core.odoo_rating.service.IRating_mixinService;
import cn.ibizlab.odoo.util.SearchResult;
import cn.ibizlab.odoo.util.log.IBIZLog;

/**
 * 实体[混合评级] 服务对象接口实现
 */
@Slf4j
@IBIZLog
@Service
public class Rating_mixinServiceImpl implements IRating_mixinService {

    @Autowired
    private cn.ibizlab.odoo.core.client.service.Irating_mixinClientService rating_mixinClientService;

    @Override
    public void createBatch(List<Rating_mixin> rating_mixins, int batchSize) {

                        //rating_mixinClientService.createBatch(rating_mixins,batchSize) ;

    }

    @Override
    public Rating_mixin get(Integer id) {
        Irating_mixin clientModel = rating_mixinClientService.createModel();
        clientModel.setId(id);
        rating_mixinClientService.get(clientModel) ;
        return this.convert2Domain(clientModel,null);
    }

    @Override
    public Rating_mixin get(Rating_mixin rating_mixin) {
        Rating_mixin retrating_mixin = this.get(rating_mixin.getId()) ;
    	BeanCopier copier=BeanCopier.create(retrating_mixin.getClass(), rating_mixin.getClass(), false);
        copier.copy(retrating_mixin, rating_mixin, null);
        return rating_mixin ;
    }

    @Override
    public void removeBatch(Collection<? extends Serializable> idList, int batchSize) {

        //rating_mixinClientService.removeBatch(rating_mixins) ;

    }

    @Override
    public boolean create(Rating_mixin rating_mixin) {
        boolean bOk = false ;
        Irating_mixin clientModel = this.convert2Model(rating_mixin,null);
        rating_mixinClientService.create(clientModel) ;
        this.convert2Domain(clientModel,rating_mixin);
        bOk = true ;

        return bOk ;
    }

    @Override
    public boolean update(Rating_mixin rating_mixin) {
        boolean bOk = false ;
        Irating_mixin clientModel = this.convert2Model(rating_mixin,null);
        rating_mixinClientService.update(clientModel) ;
        this.convert2Domain(clientModel,rating_mixin) ;
        bOk = true;
        return bOk ;
    }

    @Override
    public void updateBatch(List<Rating_mixin> rating_mixins, int batchSize) {

        //rating_mixinClientService.updateBatch(rating_mixins,batchSize) ;

    }

    @Override
    public boolean remove(Integer id) {
        boolean bOk = false ;
        Irating_mixin clientModel = rating_mixinClientService.createModel();
        clientModel.setId(id);
        rating_mixinClientService.remove(clientModel) ;
        bOk = true ;
        return bOk ;
    }

    /**
     * 查询集合 默认查询
     */
    @Override
    public Page<Rating_mixin> searchDefault(Rating_mixinSearchContext context) {
        List<Rating_mixin> list = new ArrayList<Rating_mixin>();
        Page<cn.ibizlab.odoo.core.client.model.Irating_mixin> clientModelList = rating_mixinClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Irating_mixin clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Rating_mixin>(list, context.getPageable(), clientModelList.getTotalElements());
    }




    public Irating_mixin convert2Model(Rating_mixin domain , Irating_mixin model) {
        if(domain == null)
            return model ;
        if(model==null){
            model = rating_mixinClientService.createModel() ;
        }

         if(domain.getRating_last_feedbackDirtyFlag())
            model.setRating_last_feedback(domain.getRating_last_feedback());
         if(domain.getRating_countDirtyFlag())
            model.setRating_count(domain.getRating_count());
         if(domain.getIdDirtyFlag())
            model.setId(domain.getId());
         if(domain.get__last_updateDirtyFlag())
            model.set__last_update(domain.get__last_update());
         if(domain.getRating_idsDirtyFlag())
            model.setRating_ids(domain.getRating_ids());
         if(domain.getRating_last_imageDirtyFlag())
            model.setRating_last_image(domain.getRating_last_image());
         if(domain.getRating_last_valueDirtyFlag())
            model.setRating_last_value(domain.getRating_last_value());
         if(domain.getDisplay_nameDirtyFlag())
            model.setDisplay_name(domain.getDisplay_name());
        return model ;
    }

    public Rating_mixin convert2Domain( Irating_mixin model ,Rating_mixin domain) {
        if(model == null)
            return domain ;
        if(domain == null){
            domain = new Rating_mixin();
        }

        if(model.getRating_last_feedbackDirtyFlag())
            domain.setRating_last_feedback(model.getRating_last_feedback());
        if(model.getRating_countDirtyFlag())
            domain.setRating_count(model.getRating_count());
        if(model.getIdDirtyFlag())
            domain.setId(model.getId());
        if(model.get__last_updateDirtyFlag())
            domain.set__last_update(model.get__last_update());
        if(model.getRating_idsDirtyFlag())
            domain.setRating_ids(model.getRating_ids());
        if(model.getRating_last_imageDirtyFlag())
            domain.setRating_last_image(model.getRating_last_image());
        if(model.getRating_last_valueDirtyFlag())
            domain.setRating_last_value(model.getRating_last_value());
        if(model.getDisplay_nameDirtyFlag())
            domain.setDisplay_name(model.getDisplay_name());
        return domain ;
    }


}
